﻿

@{
    Layout = "~/Views/Shared/_LayoutDialog.cshtml";
}
@model OL.FrameCore.Application.User.Dto.GetUserResponse

@section CSS{

}

<form class="layui-form">
    <input type="hidden" id="hidId" value="@ViewBag.UserId" />
    <div class="layui-tab-content page-detail">
        <div class="layui-tab-item layui-show">
            <div class="layui-row">
                <div class="layui-form-item">
                    <label class="layui-form-label">密码<span class="required">*</span></label>
                    <div class="layui-input-block">
                        <input type="password" id="tbPassword" required lay-verify="required|maxLength20" placeholder="" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-row">
                <div class="layui-form-item">
                    <label class="layui-form-label">重复密码<span class="required">*</span></label>
                    <div class="layui-input-block">
                        <input type="password" id="tbRepeatPassword" required lay-verify="required|maxLength20" placeholder="" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-row detail-submit">
                <div class="layui-layer-btn layui-layer-btn-c">
                    <a class="layui-layer-btn0" id="btnSave" lay-submit lay-filter="*">保存</a>
                    <a class="layui-layer-btn0" id="btnCanel" onclick="RetsetPassword.cancel()">取消</a>
                </div>
            </div>
        </div>
    </div>
</form>

@section Scripts{
    <script>
        var RetsetPassword = function () {
            let inited = false;
            let data = {};

            function initData() {
                layui.use(['form', 'layer'], function () {
                    var form = layui.form;
                    form.verify({
                        maxLength20: [/^.{0,20}$/, '长度最大为20'],
                        maxLength200: [/^.{0,200}$/, '长度最大为200']
                    });

                    form.on('submit(*)', function (data) {
                        var userId = $("#hidId").val();
                        var password = $("#tbPassword").val();
                        var repeatPassword = $("#tbRepeatPassword").val();

                        if (password != repeatPassword) {
                            parent.layer.msg("两次密码输入不一致");
                            return;
                        }

                        //开启loading
                        layer = layui.layer;
                        var index = layer.load(2);

                        $.ajax({
                            url: "/User/PostRetsetPassword",
                            type: "post",
                            data: { userId: userId, password: password },
                            success: function (data) {
                                layer.close(index);
                                if (data.state == 1) {
                                    parent.layer.msg("操作成功", { shade: 0.4, icon: 1 }, function () {
                                        //parent.location.reload();
                                        //刷新列表
                                        parent.layui.table.reload("table-list")

                                        var index = parent.layer.getFrameIndex(window.name);
                                        parent.layer.close(index);
                                    });
                                } else if (data.state == 0) {
                                    parent.layer.open({
                                        title: '提示'
                                        , content: "操作失败 " + data.msg
                                        , shade: 0.4
                                        , icon: 5
                                    });
                                } else {
                                    parent.layer.open({
                                        title: '提示'
                                        , content: "操作异常 " + data.msg
                                        , shade: 0.4
                                        , icon: 2
                                    });
                                }
                            }
                        });

                    });

                });
            }

            return {
                init() {//初始化
                    if (!inited) {
                        initData();
                        inited = true;
                    }
                },
                cancel() {//取消
                    var index = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(index);
                }
            };
        }();
        RetsetPassword.init();
    </script>
}

